Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Vrai-Prix8 * File : src/app/api/listings/[uid]/ai-analysis-json/route.ts9 * Module : app10 * Repository : https://git.spboucher.ai/vrai-prix11 * Created : 2026-09-0812 * Last Modified : 2026-09-0813 *14 * Author : Simon-Pierre Boucher15 * Position : Professor of Finance16 * Institution : Université du Québec en Outaouais (UQO)17 * Organization : SP Boucher18 * Website : https://spboucher.ai19 * Git : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development : dev@spboucher.ai23 * Support : support@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Vrai-Prix — téléchargement du JSON technique complet d'une analyse (profil, métadonnées, géométrie dérivée, images utilisées).43import { NextRequest, NextResponse } from "next/server";44import { getById, getLatest } from "@/lib/cost/ai/service";4546export const runtime = "nodejs";4748export async function GET(req: NextRequest, { params }: { params: Promise<{ uid: string }> }) {49 const { uid } = await params;50 const id = req.nextUrl.searchParams.get("id");51 const v = id ? getById(id) : getLatest(decodeURIComponent(uid));52 if (!v || v.listingUid !== decodeURIComponent(uid) || !v.analysis) return NextResponse.json({ error: "aucune analyse complète" }, { status: 404 });53 const body = JSON.stringify({ ...v.analysis, merged_facts: v.merged, mapping: v.mapping, conflicts: v.conflicts, overrides: v.overrides, cost_snapshot_date: v.costSnapshotDate, estimate_id: v.estimate?.id ?? null, combined_confidence: v.combined }, null, 2);54 const slug = decodeURIComponent(uid).replace(/[^a-zA-Z0-9]+/g, "-");55 return new NextResponse(body, { headers: { "Content-Type": "application/json; charset=utf-8", "Content-Disposition": `attachment; filename="vrai-prix-analyse-ia-${slug}-v${v.version}.json"`, "Cache-Control": "no-store" } });56}57